package com.cheng.example.geektime.designpatterns.j60.v1;


import java.util.HashMap;
import java.util.Map;


/**
 * 无状态模式
 */
public class StrategyFactory {
    private static final Map<String, Strategy> strategies = new HashMap<>();

    static {
        strategies.put("A", new ConcreteStrategyA());
        strategies.put("B", new ConcreteStrategyB());
    }

    public static Strategy getStrategy(String type) {
        if (type == null || type.isEmpty()) {
            throw new IllegalArgumentException("type should not be empty.");
        }
        return strategies.get(type);
    }
}

/**
 * 有状态模式
 */

//public class StrategyFactory {
//    public static Strategy getStrategy(String type) {
//        if (type == null || type.isEmpty()) {
//            throw new IllegalArgumentException("type should not be empty.");
//        }
//
//        if (type.equals("A")) {
//            return new ConcreteStrategyA();
//        } else if (type.equals("B")) {
//            return new ConcreteStrategyB();
//        }
//
//        return null;
//    }
//}